# util_test.rb

require 'test/unit'
require File.dirname(__FILE__) + '/../fatspider'

class FatSpiderTest < Test::Unit::TestCase
  
  def test_spike
    assert_equal 2, 1 + 1
  end
  
  def test_host_of
    assert_equal 'http://www.csdn.net', FatUtil::host_of('http://www.csdn.net')
    assert_equal 'http://www.csdn.net', FatUtil.host_of('http://www.csdn.net/')    
    assert_equal 'http://www.csdn.net:8888', FatUtil.host_of('http://www.csdn.net:8888/')
    assert_equal 'http://www.csdn.net:8888', FatUtil.host_of('http://www.csdn.net:8888')
    assert_equal 'http://www.csdn.net', FatUtil.host_of('http://www.csdn.net/blog/12354.aspx')
    assert_equal 'ftp://apress.com', FatUtil.host_of('ftp://apress.com/s1232124/')
    assert_equal 'http://localhost:3000', FatUtil.host_of('http://localhost:3000/admin/list')
    assert_equal 'http://192.168.9.18:8888', FatUtil.host_of('http://192.168.9.18:8888/help/move.html')
    assert_equal '', FatUtil.host_of('')    
  end
  
  def test_cache_documents
    phc = ParsedHtmlCache.new
    phc.parse(['http://www.csdn.net', 'http://www.dzone.com'])
    assert_equal Hpricot::Doc, phc['http://www.csdn.net'].class 
  end

end

